package com.iven.xie.redis.controller;

import com.iven.xie.redis.beans.DbDataInfo;
import com.iven.xie.redis.beans.RedisConfig;
import com.iven.xie.redis.beans.ResObject;
import com.iven.xie.redis.service.DataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author iven.xie
 */
@Api(tags = "redis数据列表接口")
@RestController
@RequestMapping("api/data")
@Slf4j
public class DataController {

    @Autowired
    private DataService dataService;

    @ApiOperation(value = "根据服务redis配置获取信息", notes = "根据服务redis配置获取信息")
    @PostMapping(value = "/db/list")
    public ResObject<List<DbDataInfo>> getDbList(@RequestBody RedisConfig config) throws Exception {
        if (config == null) {
            throw new Exception("redis配置不能为空");
        }
        return ResObject.success(dataService.getDbList(config));
    }

}
